package sk.tuke.serviceDao;

import org.hibernate.Query;
import org.hibernate.Session;

import sk.tuke.persistance.DepartmentPo;
import sk.tuke.persistance.InsurancePo;

public class BusinessManagementDao extends AbstractDao {

	public InsurancePo createInsurance(Integer number, String name, String phone, String email, String contactPerson, String street, Integer streetNum,
			String city, Integer zip, String state) {
		Session session = getSession();
		session.beginTransaction();

		InsurancePo insurancePo = new InsurancePo();
		insurancePo.setCity(city);
		insurancePo.setContactPerson(contactPerson);
		insurancePo.setEmail(email);
		insurancePo.setName(name);
		insurancePo.setNumber(number);
		insurancePo.setPhone(phone);
		insurancePo.setState(state);
		insurancePo.setStreet(street);
		insurancePo.setStreetNum(streetNum);
		insurancePo.setZip(zip);

		session.save(insurancePo);
		session.getTransaction().commit();
		session.close();
		return insurancePo;
	}

	public InsurancePo getInsurance(Integer insuranceNumber) {
		Session session = getSession();
		Query query = session.createQuery("select u from InsurancePo u where number = :insuranceNumber");
		query.setLong("insuranceNumber", insuranceNumber);
		InsurancePo insurance = (InsurancePo) query.uniqueResult();
		return insurance;
	}

	public DepartmentPo getDepartment(Integer departmentNumber) {
		Session session = getSession();
		Query query = session.createQuery("select u from DepartmentPo u where number = :departmentNumber");
		query.setInteger("departmentNumber", departmentNumber);
		DepartmentPo department = (DepartmentPo) query.uniqueResult();
		return department;
	}

}
